#include <fcntl.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
using namespace std;

#define MAX_BUF 1024

int main()
{
    int fd;
    char * myfifo = "/tmp/myfifo";
    char buf[MAX_BUF];
    ofstream myfile;
    myfile.open ("topOutput.txt");
    fd = open(myfifo, O_RDONLY);
    while (true) 
    {
      read(fd, buf, MAX_BUF);
     // printf(" %s\n", buf);
      myfile << buf << endl;

      if (strcmp (buf,"End") == 0)
       break;
      strcpy(buf,""); 
    }
    myfile.close();
    close(fd);

    return 0;
}
